package com.ymatou.i.accounting.api.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.i.accounting.api.parameter.AccountEntryBean;
import com.ymatou.i.accounting.api.parameter.GetAccountEntryBean;
import com.ymatou.i.accounting.api.service.GetAccountEntryCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.AccountCallService;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;
/**
*获取账户资金流水接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAccountEntry{
	private static GetAccountEntryBean getaccountentryBean;
	private static GetAccountEntryCall getaccountentryCall;
	private static int user_id;
	private static int account_type;
	private static int biz_code;
	private static String biz_no;
	private static int entry_type;
	private static String app_id;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取账户资金流水接口");
		try {
			List<HashMap>m=new AccountDefaultWapper().selectAccountEntryAndInfo();
			int index=0;
			 user_id=(Integer) m.get(index).get("iUserId");
			 account_type=(Integer) m.get(index).get("iAccountType");
			 biz_code=(Integer) m.get(index).get("BizCode");
			 biz_no =(String) m.get(index).get("BizNo");
			 entry_type=(Integer) m.get(index).get("EntryType");
			 app_id=(String) m.get(index).get("AppId");
//			 Logger.debug(m);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	@Before
	public void caseUp() {
		getaccountentryBean=new GetAccountEntryBean();
		getaccountentryCall=new GetAccountEntryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getaccountentryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetAccountEntry_001() {
		Logger.start(true,"获取账户资金流水成功");
		try {
			int userId=user_id;
			int type=account_type;
			int bizCode=biz_code;
			String bizNo =biz_no;
			int entryType=entry_type;
			String appId=app_id;
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);		
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			
			//查询数据库
			 List<YmtAccountEntry> dbEntry= new AccountDefaultWapper().selectAccountEntry(userId,bizNo,type);
//			 Logger.debug(FormatUtil.beanToGSONString(dbEntry));
			//接口返回数据			 
			 AccountEntryBean retrunData=getaccountentryCall.getReturnAccountEntry();
			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");

			Logger.verifyEquals(dbEntry.get(0).getAccountid(),retrunData.getAccountId(),"验证接口返回AccountId跟数据库是否一致");	
			Logger.verifyEquals(dbEntry.get(0).getEntryid(),retrunData.getEntryId(),"验证接口返回EntryId跟数据库是否一致");				
			Logger.verifyEquals(0,dbEntry.get(0).getAmount().compareTo(retrunData.getAmount()),"验证接口返回Amount:"+retrunData.getAmount()+"跟数据库是否一致");	
			Logger.verifyEquals(0,dbEntry.get(0).getFreezeamount().compareTo(retrunData.getFreezeAmount()),"验证接口返回FreezeAmount:"+retrunData.getFreezeAmount()+"跟数据库是否一致");	
			Logger.verifyEquals(0,dbEntry.get(0).getAvailamount().compareTo(retrunData.getAvailAmount()),"验证接口返回AvailAmount:"+retrunData.getAvailAmount()+"跟数据库是否一致");				
			Logger.verifyEquals(dbEntry.get(0).getEntrytype(),retrunData.getEntryType(),"验证接口返回EntryType跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getUserid(),retrunData.getUserId(),"验证接口返回UserId跟数据库是否一致");	
			Logger.verifyEquals(dbEntry.get(0).getBizcode(),retrunData.getBizCode(),"验证接口返回BizCode跟数据库是否一致");	
			Logger.verifyEquals(dbEntry.get(0).getBizno(),retrunData.getBizNo(),"验证接口返回BizNo跟数据库是否一致");	
			Logger.verifyEquals(dbEntry.get(0).getOriginalno(),retrunData.getOriginalNo(),"验证接口返回OriginalNo跟数据库是否一致");	
			Logger.verifyEquals(YMTDateUtil.getFormatTime(dbEntry.get(0).getAccountingdate(),"yyyy-MM-dd HH:mm:ss"),retrunData.getAccountingDate(),"验证接口返回AccountingDate跟数据库是否一致");	
			
			Logger.verifyEquals(YMTDateUtil.getFormatTime(dbEntry.get(0).getUpdatetime(),"yyyy-MM-dd HH:mm:ss"),retrunData.getUpdateTime(),"验证接口返回UpdateTime跟数据库是否一致");	
			Logger.verifyEquals(YMTDateUtil.getFormatTime(dbEntry.get(0).getCreatetime(),"yyyy-MM-dd HH:mm:ss"),retrunData.getCreateTime(),"验证接口返回CreateTime跟数据库是否一致");	
			
			Logger.verifyEquals(dbEntry.get(0).getOperator(),retrunData.getOperator(),"验证接口返回Operator跟数据库是否一致");	
			Logger.verifyEquals(dbEntry.get(0).getMemo(),retrunData.getMemo(),"验证接口返回Memo跟数据库是否一致");	
			Logger.verifyEquals(dbEntry.get(0).getAppid(),retrunData.getAppId(),"验证接口返回AppId跟数据库是否一致");	
			Logger.verifyEquals(dbEntry.get(0).getServerip(),retrunData.getServerIp(),"验证接口返回ServerIp跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getClientip(),retrunData.getClientIp(),"验证接口返回ClientIp跟数据库是否一致");
			Logger.verifyEquals(dbEntry.get(0).getRequestid(),retrunData.getRequestId(),"验证接口返回RequestId跟数据库是否一致");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_002() {
		Logger.start(false,"账户类型不存在,获取资金流水为空");
		try {
			int userId=user_id;
			int type=9;
			int bizCode=100001;
			String bizNo ="4352f30d-7c15-4de5-8957-635bf1000020926";
			int entryType=1;
			String appId="StressTest";		
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);		
			
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			

			Logger.verifyEquals(ECode.ACCOUNT_NOT_FOUND_CODE, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyEquals(ECode.ACCOUNT_NOT_EXIST, getaccountentryCall.getMsg(), "验证msg");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_003() {
		Logger.start(false,"业务编码不存在,,获取资金流水返回为空");
		try {
			int userId=user_id;
			int type=account_type;
			int bizCode=900002;
			String bizNo ="4352f30d-7c15-4de5-8957-635bf1000020926";
			int entryType=1;
			String appId="StressTest";		
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);		
			
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_004() {
		Logger.start(false,"业务流水号不存在,,获取资金流水返回为空");
		try {
			int userId=user_id;
			int type=account_type;
			int bizCode=100001;
			String bizNo ="4352f30d-7c15-";
			int entryType=1;
			String appId="StressTest";		
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);		
			
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_005() {
		Logger.start(false,"流水类型不存在,,获取资金流水返回为空");
		try {
			int userId=user_id;
			int type=account_type;
			int bizCode=100001;
			String bizNo ="4352f30d-7c15-4de5-8957-635bf100002092";
			int entryType=1;
			String appId="StressTest";		
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);		
			
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	//@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_006() {
		Logger.start(false,"应用编号不存在,,获取资金流水返回为空");
		try {
			int userId=user_id;
			int type=account_type;
			int bizCode=biz_code;
			String bizNo =biz_no;
			int entryType=entry_type;
			String appId="xxx";			
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);		
			
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			

			Logger.verifyEquals(0, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyIsNull(getaccountentryCall.getData(), "验证返回data为null");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_007() {
		Logger.start(false,"用户id为空,,获取资金流水返回为空");
		try {
			int type=0;
			int bizCode=100001;
			String bizNo ="4352f30d-7c15-4de5-8957-635bf100002092";
			int entryType=1;
			String appId="StressTest";		
			//getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			getaccountentryBean.setAppId(appId);		
			
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			

			Logger.verifyEquals(ECode.ACCOUNT_NOT_FOUND_CODE, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyEquals(ECode.ACCOUNT_NOT_EXIST, getaccountentryCall.getMsg(), "验证msg");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetAccountEntry_008() {
		Logger.start(false,"AppId为空,,获取资金流水返回为空");
		try {
			int userId=319;
			int type=0;
			int bizCode=100001;
			String bizNo ="4352f30d-7c15-4de5-8957-635bf100002092";
			int entryType=1;
			getaccountentryBean.setUserId(userId);
			getaccountentryBean.setAccountType(type);
			getaccountentryBean.setBizCode(bizCode);
			getaccountentryBean.setBizNo(bizNo);
			getaccountentryBean.setEntryType(entryType);
			//getaccountentryBean.setAppId(appId);		
			
			getaccountentryCall.setData(getaccountentryBean);
			getaccountentryCall.callService();			

			Logger.verifyEquals(2, getaccountentryCall.getStatuscode(), "验证code");
			Logger.verifyEquals("AppId不能为空！", getaccountentryCall.getMsg(), "验证msg");		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}